﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EFS.RC.ClientPlatform.UI
{
	/// <summary>
	/// Interaction logic for Connect.xaml
	/// </summary>
	public partial class Connect : Window
	{
		#region Composition
		#endregion

		#region Delegates

		/// <summary>
		/// TryAgain event delegate
		/// </summary>
		public delegate void TryAgain();

		/// <summary>
		/// TryAgain delegate registrar
		/// </summary>
		public TryAgain OnTryAgain = null;

		/// <summary>
		/// TryAgain event delegate
		/// </summary>
		public delegate void GivedUp();

		/// <summary>
		/// GivedUp delegate registrar
		/// </summary>
		public GivedUp OnGivedUp = null;

		#endregion

		#region Usage

		//Show rpogress
		public void ShowProgress(System.String progressTitle, System.String progressMessage)
		{
			menuItemTools.IsEnabled = false;
			buttonTryAgain.Visibility = System.Windows.Visibility.Hidden;
			progressBar.Visibility = System.Windows.Visibility.Visible;
			Title = progressTitle;
			Message = progressMessage;
		}

		//Show error	
		public void ShowError(System.String errorTitle, System.String errorMessage)
		{
			menuItemTools.IsEnabled = false;
			buttonTryAgain.Visibility = System.Windows.Visibility.Hidden;
			progressBar.Visibility = System.Windows.Visibility.Hidden;
			Title = errorTitle;
			Message = errorMessage;
		}

		//Show error	
		public void ShowRetry(System.String retryTitle, System.String retryMessage)
		{
			menuItemTools.IsEnabled = true;
			buttonTryAgain.Visibility = System.Windows.Visibility.Visible;
			progressBar.Visibility = System.Windows.Visibility.Hidden;
			Title = retryTitle;
			Message = retryMessage;
		}

		/// <summary>
		/// Set message
		/// </summary>
		public System.String Message { set { textBlockMessage.Text = value; } }

		#endregion

		public Connect()
		{
			InitializeComponent();

			// hide try again
			buttonTryAgain.Visibility = System.Windows.Visibility.Hidden;
		}

		private void buttonTryAgain_Click(object sender, RoutedEventArgs e)
		{
			// show progress
			progressBar.Visibility = System.Windows.Visibility.Visible;

			if (null != OnTryAgain)
			{
				OnTryAgain();
			}
		}

		private void buttonClose_Click(object sender, RoutedEventArgs e)
		{
			buttonTryAgain.Visibility = System.Windows.Visibility.Hidden;
			progressBar.Visibility = System.Windows.Visibility.Hidden;
			buttonClose.Visibility = System.Windows.Visibility.Hidden;
			buttonTryAgain.Visibility = System.Windows.Visibility.Hidden;
			Title = "Closing";
			Message = "Closing";

			if (null != OnGivedUp)
			{
				OnGivedUp();
			}
		}

		private void menuTools_Click(object sender, RoutedEventArgs e)
		{
			Settings settings = new Settings(); 
			settings.Owner = this;
			settings.ShowDialog();
		}
	}
}
